import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Tabs } from 'src/app/shared/components';
import { Ad, Product } from 'src/app/shared/domain';

// 使用了providedIn: 'root'可以减少打包的体积，也可以不在module中的providers上申明这个服务也能使用

@Injectable({
  providedIn: 'root',
})
export class HomeContainerService {
  tabs: Tabs[] = [
    { title: '推荐', link: 'recommend' },
    { title: '热门', link: 'hot' },
    { title: '鞋包', link: 'shoes' },
    { title: '手机', link: 'phone' },
    { title: '食品', link: 'food' },
    { title: '母婴', link: 'baby' },
    { title: '男装', link: 'men' },
    { title: '百货', link: '' },
    { title: '内衣', link: '' },
    { title: '电器', link: '' },
    { title: '家纺', link: '' },
    { title: '水果', link: '' },
    { title: '家具', link: '' },
    { title: '美妆', link: '' },
    { title: '家装', link: '' },
    { title: '运动', link: '' },
    { title: '车品', link: '' },
    { title: '医药', link: '' },
    { title: '电脑', link: '' },
    { title: '海淘', link: '' },
    { title: '饰品', link: '' },
    { title: '玩乐', link: '' },
  ];

  constructor(private http: HttpClient) {}
  getTabs(): Tabs[] {
    return this.tabs;
  }
  getAds() {
    return this.http.get<Ad>('/api/ads');
  }
  getProducts() {
    return this.http.get<Product>('/api/products', {
      params: {
        pageNum: 1,
        pageSize: 5,
      },
    });
  }
}
